<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>libspotify: search.c</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">libspotify
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">search.c</div>  </div>
</div><!--header-->
<div class="contents">
<p>The search.c example shows how you can use search functions. It is part of the spshell program</p>
<div class="fragment"><pre class="fragment">
<span class="preprocessor">#include &lt;string.h&gt;</span>

<span class="preprocessor">#include &quot;spshell.h&quot;</span>
<span class="preprocessor">#include &quot;cmd.h&quot;</span>


<span class="keyword">static</span> <span class="keywordtype">void</span> print_album(<a class="code" href="group__types.html#ga6fd3e5de729c429fef3ff18ece6dcfad" title="An album handle.">sp_album</a> *album)
{
    printf(<span class="stringliteral">&quot;  Album \&quot;%s\&quot; (%d)\n&quot;</span>,
           <a name="a0"></a><a class="code" href="group__album.html#ga0e828c991a8184d60026513f944e19ad">sp_album_name</a>(album),
           <a name="a1"></a><a class="code" href="group__album.html#ga2aadf934b0af43c3ef6ee98b6a8065fd">sp_album_year</a>(album));
}

<span class="keyword">static</span> <span class="keywordtype">void</span> print_artist(<a class="code" href="group__types.html#ga31764fbd69618c10be173c6c03d4c1bc" title="An artist handle.">sp_artist</a> *artist)
{
    printf(<span class="stringliteral">&quot;  Artist \&quot;%s\&quot;\n&quot;</span>, <a name="a2"></a><a class="code" href="group__artist.html#gad2895555bb48514986823733a7afe5e2">sp_artist_name</a>(artist));
}

<span class="keyword">static</span> <span class="keywordtype">void</span> print_search(<a class="code" href="group__types.html#gac95893a6b23d4b19f6f149eed6ead1fd" title="A handle to a search result.">sp_search</a> *search)
{
    <span class="keywordtype">int</span> i;

    printf(<span class="stringliteral">&quot;Query          : %s\n&quot;</span>, <a name="a3"></a><a class="code" href="group__search.html#ga127e9c2bf98e3602ecfc2926b9d242bf">sp_search_query</a>(search));
    printf(<span class="stringliteral">&quot;Did you mean   : %s\n&quot;</span>, <a name="a4"></a><a class="code" href="group__search.html#ga8561c1da8b93ecdc8f2d325a9d19199b">sp_search_did_you_mean</a>(search));
    printf(<span class="stringliteral">&quot;Tracks in total: %d\n&quot;</span>, <a name="a5"></a><a class="code" href="group__search.html#gab4e50582c517b4639fd1afd6fb011587">sp_search_total_tracks</a>(search));
    puts(<span class="stringliteral">&quot;&quot;</span>);

    <span class="keywordflow">for</span> (i = 0; i &lt; <a name="a6"></a><a class="code" href="group__search.html#ga1dd18cf7b3b3b7f4bf6e92a2140378d0">sp_search_num_tracks</a>(search); ++i)
        print_track(<a name="a7"></a><a class="code" href="group__search.html#gae9da7ca59ce0bbd73f7bcef4e15c4da8">sp_search_track</a>(search, i));

    puts(<span class="stringliteral">&quot;&quot;</span>);

    <span class="keywordflow">for</span> (i = 0; i &lt; <a name="a8"></a><a class="code" href="group__search.html#ga0c456a6396c4c05fbc8677ea641ef1f7">sp_search_num_albums</a>(search); ++i)
        print_album(<a name="a9"></a><a class="code" href="group__search.html#ga4ba7723e70db0c6a4569c4bcd44f0e98">sp_search_album</a>(search, i));

    puts(<span class="stringliteral">&quot;&quot;</span>);

    <span class="keywordflow">for</span> (i = 0; i &lt; <a name="a10"></a><a class="code" href="group__search.html#gabd375a613c2dadecad8c13f8aca6f2d3">sp_search_num_artists</a>(search); ++i)
        print_artist(<a name="a11"></a><a class="code" href="group__search.html#ga79b3d532d5a20a3b2bf2a087eead7888">sp_search_artist</a>(search, i));

    puts(<span class="stringliteral">&quot;&quot;</span>);
}

<span class="keyword">static</span> <span class="keywordtype">void</span> SP_CALLCONV search_complete(<a class="code" href="group__types.html#gac95893a6b23d4b19f6f149eed6ead1fd" title="A handle to a search result.">sp_search</a> *search, <span class="keywordtype">void</span> *userdata)
{
    <span class="keywordflow">if</span> (<a name="a12"></a><a class="code" href="group__search.html#ga7cf655e37a823f952d30270d4fb60f10">sp_search_error</a>(search) == <a name="a13"></a><a class="code" href="group__error.html#ggafd27986ce4cd9eeaeca8adda83c9eb6ba16cb277dc84328e4b2c0cf6d5a0c0b8d" title="No errors encountered.">SP_ERROR_OK</a>)
        print_search(search);
    <span class="keywordflow">else</span>
        fprintf(stderr, <span class="stringliteral">&quot;Failed to search: %s\n&quot;</span>,
                <a name="a14"></a><a class="code" href="group__error.html#ga983dee341d3c2008830513b7cffe7bf3">sp_error_message</a>(<a class="code" href="group__search.html#ga7cf655e37a823f952d30270d4fb60f10">sp_search_error</a>(search)));

    <a name="a15"></a><a class="code" href="group__search.html#ga4e01d43067d9f8c533c985f90143821b">sp_search_release</a>(search);
    cmd_done();
}



<span class="keyword">static</span> <span class="keywordtype">void</span> search_usage(<span class="keywordtype">void</span>)
{
    fprintf(stderr, <span class="stringliteral">&quot;Usage: search &lt;query&gt;\n&quot;</span>);
}


<span class="keywordtype">int</span> cmd_search(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
{
    <span class="keywordtype">char</span> query[1024];
    <span class="keywordtype">int</span> i;

    <span class="keywordflow">if</span> (argc &lt; 2) {
        search_usage();
        <span class="keywordflow">return</span> -1;
    }

    query[0] = 0;
    <span class="keywordflow">for</span>(i = 1; i &lt; argc; i++)
        snprintf(query + strlen(query), <span class="keyword">sizeof</span>(query) - strlen(query), <span class="stringliteral">&quot;%s%s&quot;</span>,
             i == 1 ? <span class="stringliteral">&quot;&quot;</span> : <span class="stringliteral">&quot; &quot;</span>, argv[i]);

    <a name="a16"></a><a class="code" href="group__search.html#ga2f64dfbcc1313e7d5179998cb28208d4">sp_search_create</a>(g_session, query, 0, 100, 0, 100, 0, 100, 0, 100, SP_SEARCH_STANDARD, &amp;search_complete, NULL);
    <span class="keywordflow">return</span> 0;
}


<span class="keywordtype">int</span> cmd_whatsnew(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
{
    <a class="code" href="group__search.html#ga2f64dfbcc1313e7d5179998cb28208d4">sp_search_create</a>(g_session, <span class="stringliteral">&quot;tag:new&quot;</span>, 0, 0, 0, 250, 0, 0, 0, 0, SP_SEARCH_STANDARD, &amp;search_complete, NULL);
    <span class="keywordflow">return</span> 0;
}
</pre></div> </div><!-- contents -->
<hr size="1"><address style="text-align: right;"><small>
Generated on Wed May 23 2012 11:04:07.<br>
Copyright &copy; 2006&ndash;2012 Spotify Ltd</small></address>
</body>
</html>
